/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TextField
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Stage
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.pay;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.common.business.RechargeCardUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.SpringUtil;
import com.gys.common.util.ValidationUtil;
import com.gys.controller.BaseController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.controller.pay.PayController;
import com.gys.data.pay.RechargeCardOutData;
import com.gys.view.pay.CzkView;
import de.felixroske.jfxsupport.FXMLController;
import java.math.BigDecimal;
import java.net.URL;
import java.util.HashMap;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class CzkController
extends BaseController
implements Initializable {
    @FXML
    private AnchorPane pane;
    @FXML
    public TextField czkNo;
    @FXML
    public TextField balanceAmount;
    @FXML
    public TextField amount;
    @FXML
    public TextField name;
    @FXML
    public TextField sex;
    @FXML
    public TextField phone;
    @FXML
    public TextField address;
    @Autowired
    private PayController payController;
    private Timer timer = new Timer();

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.czkNo.requestFocus();
        this.timer.schedule(new TimerTask(){

            @Override
            public void run() {
                CzkView view = SpringUtil.getBean(CzkView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent event) {
                        if (event.getCode() == KeyCode.ENTER) {
                            CzkController.this.search();
                            return;
                        }
                    }
                });
            }
        }, 1000L);
        this.czkNo.setText("");
        this.amount.setText("");
        this.balanceAmount.setText("");
        this.name.setText("");
        this.sex.setText("");
        this.phone.setText("");
        this.address.setText("");
    }

    @FXML
    private void sureAction() {
        if (ObjectUtil.isEmpty(this.amount.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u8f93\u5165\u4ed8\u6b3e\u91d1\u989d\uff01");
            alert.showAndWait();
            return;
        }
        if (!ValidationUtil.checkAmount(this.amount.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4ed8\u6b3e\u91d1\u989d\u4e0d\u5408\u6cd5\uff01");
            alert.showAndWait();
            return;
        }
        if (ObjectUtil.isEmpty(this.balanceAmount.getText())) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u5f53\u524d\u4f59\u989d\u4e3a\u7a7a");
            alert.showAndWait();
            return;
        }
        if (new BigDecimal(this.amount.getText()).compareTo(new BigDecimal(this.balanceAmount.getText())) > 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4ed8\u6b3e\u91d1\u989d\u5927\u4e8e\u4f59\u989d\uff01");
            alert.showAndWait();
            return;
        }
        if (new BigDecimal(this.amount.getText()).compareTo(new BigDecimal(this.payController.getDsAmount().getText())) > 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4ed8\u6b3e\u91d1\u989d\u4e0d\u80fd\u5927\u4e8e\u5f85\u4ed8\u91d1\u989d");
            alert.showAndWait();
            return;
        }
        this.payController.refreshAmount("8000", this.amount.getText());
        this.payController.setCzkNo(this.czkNo.getText());
        this.payController.setCzkAmount(this.amount.getText());
        this.pane.getScene().getWindow().hide();
    }

    @FXML
    private void search() {
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("gsrcId", this.czkNo.getText());
        HttpJson rsp = RechargeCardUtil.getCardDetail(param);
        RechargeCardOutData outData = new RechargeCardOutData();
        if (rsp.isSuccess()) {
            outData = (RechargeCardOutData)JSON.parseObject((String)rsp.getMsg(), RechargeCardOutData.class);
            this.balanceAmount.setText(outData.getGsrcAmt().toString());
            this.name.setText(outData.getGsrcName());
            if ("1".equals(outData.getGsrcSex())) {
                this.sex.setText("\u7537");
            } else {
                this.sex.setText("\u5973");
            }
        } else {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", rsp.getMsg());
            alert.showAndWait();
            return;
        }
        this.phone.setText(outData.getGsrcMobile());
        this.address.setText(outData.getGsrcAddress());
    }

    @FXML
    private void cancelAction() {
        this.czkNo.setText("");
        this.amount.setText("");
        this.balanceAmount.setText("");
        this.name.setText("");
        this.sex.setText("");
        this.phone.setText("");
        this.address.setText("");
        this.pane.getScene().getWindow().hide();
    }
}

